package com.tong.lib.utils;

import android.text.TextUtils;

import com.google.gson.Gson;

/**
 * JSON解析工具 (使用Gson)
 * Created by linzb on 16-1-27.
 */
public class JsonUtil {

    //json转换成bean类
    public static <T> T fromJson(String json, Class<T> clazz) {
        if (TextUtils.isEmpty(json) || clazz == null) {
            return null;
        }
        return new Gson().fromJson(json, clazz);
    }

    //bean类转换成json字符串
    public static String toJson(Object obj) {
        if (obj == null) {
            return null;
        }
        return new Gson().toJson(obj);
    }
}
